home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxfarith.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.6 KB  |  146 lines

  1. /* Copyright (C) 1993, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxfarith.h,v 1.3 2000/09/19 19:00:36 lpd Exp $ */
  20. /* Floating point arithmetic macros for Ghostscript library */
  21.  
  22. #ifndef gxfarith_INCLUDED
  23. #  define gxfarith_INCLUDED
  24.  
  25. #include "gconfigv.h"        /* for USE_FPU */
  26. #include "gxarith.h"
  27.  
  28. /*
  29.  * The following macros replace the ones in gxarith.h on machines
  30.  * that are likely to have very slow floating point.
  31.  *
  32.  * None of these macros would be necessary if compilers had a clue
  33.  * about generating good floating point comparisons on machines with
  34.  * slow (or no) floating point hardware.
  35.  */
  36.  
  37. # if USE_FPU <= 0 && arch_floats_are_IEEE && (arch_sizeof_float == arch_sizeof_int || arch_sizeof_float == arch_sizeof_long)
  38.  
  39. #  if arch_sizeof_float == arch_sizeof_int
  40. typedef int _f_int_t;
  41. typedef uint _f_uint_t;
  42.  
  43. #  else                /* arch_sizeof_float == arch_sizeof_long */
  44. typedef long _f_int_t;
  45. typedef ulong _f_uint_t;
  46.  
  47. #  endif
  48. #  define _f_as_int(f) *(const _f_int_t *)(&(f))
  49. #  define _f_as_uint(f) *(const _f_uint_t *)(&(f))
  50.  
  51. #  if arch_sizeof_double == arch_sizeof_int
  52. #    define _d_int_t int
  53. #  else
  54. #   if arch_sizeof_double == arch_sizeof_long
  55. #    define _d_int_t long
  56. #   endif
  57. #  endif
  58. #  define _d_uint_t unsigned _d_int_t
  59. #  define _d_as_int(f) *(const _d_int_t *)(&(d))
  60. #  define _d_as_uint(f) *(const _d_uint_t *)(&(d))
  61.  
  62. #  define _ftest(v,f,n)\
  63.      (sizeof(v)==sizeof(float)?(f):(n))
  64. #  ifdef _d_int_t
  65. #    define _fdtest(v,f,d,n)\
  66.     (sizeof(v)==sizeof(float)?(f):sizeof(v)==sizeof(double)?(d):(n))
  67. #  else
  68. #    define _fdtest(v,f,d,n)\
  69.     _ftest(v,f,n)
  70. #  endif
  71.  
  72. #  undef is_fzero
  73. #  define is_fzero(f)    /* must handle both +0 and -0 */\
  74.      _fdtest(f, (_f_as_int(f) << 1) == 0, (_d_as_int(f) << 1) == 0,\
  75.        (f) == 0.0)
  76.  
  77. #  undef is_fzero2
  78. #  define is_fzero2(f1,f2)\
  79.      (sizeof(f1) == sizeof(float) && sizeof(f2) == sizeof(float) ?\
  80.       ((_f_as_int(f1) | _f_as_int(f2)) << 1) == 0 :\
  81.       (f1) == 0.0 && (f2) == 0.0)
  82.  
  83. #  undef is_fneg
  84. #  if arch_is_big_endian
  85. #    define _is_fnegb(f) (*(const byte *)&(f) >= 0x80)
  86. #  else
  87. #    define _is_fnegb(f) (((const byte *)&(f))[sizeof(f) - 1] >= 0x80)
  88. #  endif
  89. #  if arch_sizeof_float == arch_sizeof_int
  90. #    define is_fneg(f)\
  91.        (sizeof(f) == sizeof(float) ? _f_as_int(f) < 0 :\
  92.     _is_fnegb(f))
  93. #  else
  94. #    define is_fneg(f) _is_fnegb(f)
  95. #  endif
  96.  
  97. #  define IEEE_expt 0x7f800000    /* IEEE exponent mask */
  98. #  define IEEE_f1 0x3f800000    /* IEEE 1.0 */
  99.  
  100. #  undef is_fge1
  101. #  if arch_sizeof_float == arch_sizeof_int
  102. #    define is_fge1(f)\
  103.        (sizeof(f) == sizeof(float) ?\
  104.     (_f_as_int(f)) >= IEEE_f1 :\
  105.     (f) >= 1.0)
  106. #  else                /* arch_sizeof_float == arch_sizeof_long */
  107. #    define is_fge1(f)\
  108.        (sizeof(f) == sizeof(float) ?\
  109.     (int)(_f_as_int(f) >> 16) >= (IEEE_f1 >> 16) :\
  110.     (f) >= 1.0)
  111. #  endif
  112.  
  113. #  undef f_fits_in_ubits
  114. #  undef f_fits_in_bits
  115. #  define _f_bits(n) (4.0 * (1L << ((n) - 2)))
  116. #  define f_fits_in_ubits(f, n)\
  117.     _ftest(f, _f_as_uint(f) < (_f_uint_t)IEEE_f1 + ((_f_uint_t)(n) << 23),\
  118.       (f) >= 0 && (f) < _f_bits(n))
  119. #  define f_fits_in_bits(f, n)\
  120.     _ftest(f, (_f_as_uint(f) & IEEE_expt) < IEEE_f1 + ((_f_uint_t)((n)-1) << 23),\
  121.       (f) >= -_f_bits((n)-1) && (f) < _f_bits((n)-1))
  122.  
  123. # endif                /* USE_FPU <= 0 & ... */
  124.  
  125. /*
  126.  * Define sine and cosine functions that take angles in degrees rather than
  127.  * radians, hit exact values at multiples of 90 degrees, and are implemented
  128.  * efficiently on machines with slow (or no) floating point.
  129.  */
  130. double gs_sin_degrees(P1(double angle));
  131. double gs_cos_degrees(P1(double angle));
  132. typedef struct gs_sincos_s {
  133.     double sin, cos;
  134.     bool orthogonal;        /* angle is multiple of 90 degrees */
  135. } gs_sincos_t;
  136. void gs_sincos_degrees(P2(double angle, gs_sincos_t * psincos));
  137.  
  138. /*
  139.  * Define an atan2 function that returns an angle in degrees and uses
  140.  * the PostScript quadrant rules.  Note that it may return
  141.  * gs_error_undefinedresult.
  142.  */
  143. int gs_atan2_degrees(P3(double y, double x, double *pangle));
  144.  
  145. #endif /* gxfarith_INCLUDED */
  146.